package mapReduce.demo04_IOFormat.inputFormat;

import mapReduce.util.JobSubmit;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.NLineInputFormat;

import java.io.IOException;

public class NLineInputFormatApp {

    public static class NIFMapper extends Mapper<LongWritable, Text,Text,Text>{

        Text outKey = new Text();
        Text outValue = new Text();

        @Override
        protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
            String line = value.toString();
            String[] fields = line.split(",");

            outKey.set(fields[0]);
            outValue.set(fields[1]);

            context.write(outKey,outValue);

        }

        public static void main(String[] args) {
            JobSubmit.setLineSum(3);
            JobSubmit.submitBaseJob(NLineInputFormatApp.class,args,0, NLineInputFormat.class);
        }
    }

}
